// 跳转详情
function toNewsDet(e) {
    location.href = 'article_details.html?articleid=' + e;
}
layui.use(['layer', 'laypage'], function() {
    var layer = layui.layer;
    var laypage = layui.laypage;
    var exnr = null;
    var pageOimh = {
        page: 1,
        rows: 10,
    };
    $('.nav_ul li').click(function(e) {
        $('.nav_ul li').removeClass('nav_bg_zx');
        $(this).addClass('nav_bg_zx');
        exnr = layer.load();
        pageOimh.page = 1;
        var codeStr = e.target.innerText;
        $('.information-title').text(codeStr);
        sessionStorage.setItem('zx', codeStr);
        queryBmfv();
    });
    queryBmfv();
    function queryBmfv() {
        var codeStr = sessionStorage.getItem('zx');
        $('.information-title').text(codeStr);
        if (!codeStr) {
            pageOimh.code = 'ZCRD';
            $('.information-title').text('政策法规');
            $('.nav_ul li').first().addClass('nav_bg_zx');
        } else {
            if (codeStr == '政策法规') {
                pageOimh.code = 'ZCRD';
            } else if (codeStr == '企业对接') {
                pageOimh.code = 'TZGG';
            } else if (codeStr == '行业动态') {
                pageOimh.code = 'JRZX_JRXW';
            } else if (codeStr == '增值服务') {
                pageOimh.code = 'SJZCRD';
            }
            // 默认选中状态
            $('.nav_ul li').each(function() {
                if ($(this).find('span').text() == codeStr) {
                    $(this).addClass('nav_bg_zx')
                }
            });
        }
        getHttp('mh/app/xw/getNewXwPage', pageOimh, function(d) {
            $('#news_body_item').html($.templates('#news_jsRender').render(d));
            setTimeout(function() {
                layer.close(exnr);
            }, 800)
            // 分页
            laypage.render({
                elem: 'pageDtia', //注意，这里的 test1 是 ID，不用加 # 号
                count: d.total, //数据总数，从服务端得到
                limit: pageOimh.rows,
                curr: pageOimh.page,
                theme: '#0487ff',
                jump: function(obj, first) {
                    //首次不执行
                    if (!first) {
                        pageOimh.page = obj.curr;
                        pageOimh.rows = obj.limit;
                        queryBmfv();
                    }
                }
            });
        });
        layer.close(exnr);
    }

    // 日期对比
    function duibi(a, flag) {
        var arr = a.split("-");
        var starttime = new Date(arr[0], arr[1], arr[2]);
        var starttimes = starttime.getTime();
        var date = new Date();
        var YY = date.getFullYear() + '-';
        var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
        var today = YY + MM + DD
        var arrs = today.split("-");
        var endTime = new Date(arrs[0], arrs[1], arrs[2]);
        var endTimes = endTime.getTime();
        // 进行日期比较
        if (endTimes == starttimes) {
            flag = "true";
            return flag;
        } else {
            flag = "false";
            return flag;
        }
    }
});
